<script>
    layui.use(['layer', 'table','tree','form'], function () {
        var table = layui.table;

        var dataTable = table.render({
            elem: '#dataTable'
            , height: 500
            , url: "{{ route('admin.system.permission.data') }}"
            , page: true
            , cols: [[
                {field: 'id', title: 'ID', width: 80, templet: '#auto'}
                , {field: 'power_name', title: '名称'}
                , {field: 'name', title: 'url'}
                , {field: 'p_power_name', title: '父级权限'}
                , {fixed: 'right', title: '操作', width: 220, align: 'center', toolbar: '#options'}
            ]]
        });

        $('#search').click(function () {
            var name = $('#name').val();
            dataTable.reload({
                where: {
                    name: name
                },
                page: {curr: 1}
            });
        });

        $('#refresh').click(function () {
            var name = $('#name').val();
            dataTable.reload({
                where: {
                    name: name
                },
                page: {curr: 1}
            });
        });

        table.on('tool(dataTable)', function (obj) {
            var data = obj.data;
            var event = obj.event;
            if (event === 'add_child') {
                location.href = '/admin/system/permission/createForm/?pid=' + data.id;
                //console.log(data.id);
            }
            if (event === 'edit') {
                location.href = '/admin/system/permission/editForm/' + data.id;
                //console.log(data.id);
            }
        });
    });
</script>